package com.lottery.im.common;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import java.lang.ref.WeakReference;

public abstract class WeakReferenceHandler<T> extends Handler {
  private WeakReference<T> mReference;

  public WeakReferenceHandler(T reference) {
    super(Looper.getMainLooper());
    mReference = new WeakReference(reference);
  }

  public WeakReferenceHandler(Looper looper, T reference) {
    super(looper);
    mReference = new WeakReference(reference);
  }

  @Override
  public void handleMessage(Message msg) {
    if (mReference.get() == null) {
      return;
    }
    handleMessage(mReference.get(), msg);
  }

  protected abstract void handleMessage(T reference, Message msg);
}
